<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport"
    content="width=device-width, initial-scale=1, maximum-scale=1,minimum-scale=1, user-scalable=no" />
  <title>首页</title>
  <!-- <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" /> -->
</head>

<body>
  <a href="www.baidu.com">baidu </a>
</body>
<!-- <script>
  function createXHR() {
    if (window.XMLHttpRequest) {
      return new XMLHttpRequest();
    } else {
      return new ActiveXObject('MicroSoft.XMLHTTP');
    }
  }

  var xhr = createXHR();

  xhr.onreadystatechange = function () {
    //如果不用等于4判断一下，这个函数会执行四五次，也只有等于4的时候才是真的成功
    if (xhr.readyState == 4) {
      if (xhr.status == 200) {
        alert(xhr.responseText);
      } else {
        alert('获取数据错误,错误代码：' + xhr.status + '错误信息：' + xhr.statusText);
      }
    }

  }
  xhr.open('get', 'test.php?rand=' + Math.random(), true);
  xhr.send(null);
</script> -->
<script>
  let div = document.querySelector('a')
  div.onclick = () => {
    console.log(1);
    return false

  }
  //原型继承
  function age1(age) {
    this.age = age
  }
  let attr = new age1(20)
  age1.prototype.show = function () {
    // console.log(123);
  }

  attr.show()

  function Animal(name, color, say) {
    this.name = name;
    this.color = color;
    this.say = function () { console.log('喵喵喵'); }
  }
  var cat = new Animal('cat', 'w')
  Animal.prototype.cry = function () {
    console.log('呜呜呜');
  }
  // 利用 apply()
  function height(height, name, age) {
    this.height = height
    this.name = name;
    this.age = age;
  }
  function man(...res) {
    height.apply(this, [...res]);
  }
  var Man = new man(30, 'wozien', 12);


  // 傻瓜式继承

  function Animal() {
    this.color = "white";
    this.name = "小甜甜";
    this.age = 4;
    this.gender = "female";
  }
  var ani = new Animal();

  //定义了一个dog类
  function Dog() {

  }
  //把dog的原型指向了Animal的实例对象
  Dog.prototype = ani;

  var d = new Dog();
  fn1()
  function fn1() {
    let i = 0
    return function () {
      console.log(i);
      return i++
    }
  }


  function demo() {
    let a = 100
    return function () {
      console.log(a)
    }
  }
  let a = 200
  demo()

</script>

</html>